class Solution {
    public String multiply(String num1, String num2) {
        int[] ans = new int[num1.length() + num2.length()];
        for (int i = num1.length() - 1; i >= 0; i--) {
            int n1 = num1.charAt(i) - '0';
            for (int j = num2.length() - 1; j >= 0; j--) {
                int n2 = num2.charAt(j) - '0';
                ans[num1.length() + num2.length() - 2 - (i + j)] += n1 * n2;
            }
        }
        for (int i = 0; i < ans.length - 1; i++) {
            ans[i + 1] += ans[i] / 10;
            ans[i] %= 10;
        }
        // 打印
        StringBuilder sb = new StringBuilder();
        boolean flag = false;
        for (int i = ans.length - 1; i >= 0; i--) {
            if (ans[i] != 0 || i == 0) {
                flag = true;
            }
            if (flag) {
                sb.append(ans[i]);
            }
        }
        return sb.toString();
    }
}

class Solution {
    public String multiply(String num1, String num2) {
        num1 = new StringBuilder(num1).reverse().toString();
        num2 = new StringBuilder(num2).reverse().toString();
        int[] ans = new int[num1.length() + num2.length()];
        for (int i = 0; i < num2.length(); i++) {
            for (int j = 0; j < num1.length(); j++) {
                ans[i + j] += (num2.charAt(i) - '0') * (num1.charAt(j) - '0');
            }
        }
        for (int i = 0; i < ans.length - 1; i++) {
            ans[i + 1] += ans[i] / 10;
            ans[i] %= 10;
        }
        StringBuilder sb = new StringBuilder();
        boolean flag = false;
        for (int i = ans.length - 1; i >= 0; i--) {
            if (ans[i] != 0 || i == 0) {
                flag = true;
            }
            if (flag) {
                sb.append(ans[i]);
            }
        }
        return sb.toString();
    }
}